package day04;


import java.util.Random;
import java.util.Scanner;

/**
 * 系统自动生成一个100以内的随机数 num
 * 然后用户从键盘输入自己猜测的数字 guessNum
 * 如果guessNum>num,提示猜到了
 * 如果guessNum<num,提示猜小了
 * 否则，提示恭喜您猜对了，您共猜了几次
 */
public class GuessNumberGame {
    public static void main(String[] args) {
        //生成随机数
        Random r = new Random();
        int num = r.nextInt(100)+1;//[0,n)
        //System.out.println(num);
        Scanner sca = new Scanner(System.in);
        int count = 0;
        while(true){
            System.out.println("请输入您猜的数字(1~100):");
            int guessNum = sca.nextInt();
            count++;
            if(guessNum>num){
                System.out.println("猜大了");
            }else if(guessNum<num){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜您猜对了,您共猜了"+count+"次！");
                break;
            }
        }
    }
}
